home *** CD-ROM | disk | FTP | other *** search
- /* GCW 06/06/94 */
- /* convert a number n to a signed string to base b */
- string(n,b)
- {
- local neg,s,d;
- if (n == 0) return ("0");
- if (neg = (n<0)) n = -n;
- s = "";
- while (n)
- {
- d = n%b;
- s = ((d<10)?(d +'0'):(d+'W'))+s;
- n /= b;
- }
- return (((neg)?"-":"")+s);
- }
-
- /* convert a number n to an unsigned hexadecimal string */
- hex(n)
- {
- local s,byte,top,bottom,b,i,zero;
- s = "&";zero = TRUE;i = 4;
- b = @(newstring(4));
- in b put { n; }
- while (i>0 && zero)
- {
- i--;
- if (byte=`(b+i)) zero = FALSE;
- }
- top = byte/16; bottom = byte%16;
- if (top) s += (top<10)?(top+'0'):(top+'W');
- s += (bottom<10)?(bottom+'0'):(bottom+'W');
- while (i>0)
- {
- i--; byte = `(b+i); top = byte/16; bottom = byte%16;
- s += (top<10)?(top+'0'):(top+'W');
- s += (bottom<10)?(bottom+'0'):(bottom+'W');
- }
- return s;
- }
-